<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class AltreAddThirdOrderIdAndThirdType extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        $cFunc = function (Blueprint $table) {
            $table->string('thirdOrderId', 64)->default('')->after('offOrderId')->comment('三方订单编号');
            $table->tinyInteger('thirdOrderSource')->default(0)->after('thirdOrderId')
                  ->comment('三方订单来源 0 无 1 抖音');

            $table->index('thirdOrderId', 'idx_thirdOrderId');
        };

        // 分表库
        for ($i = 0; $i <= 99; $i++) {
            $this->name = '_' . str_pad($i, 3, 0, STR_PAD_LEFT);
            Schema::connection("mysqlOrder")->table('order' . $this->name, $cFunc);
            Schema::connection("mysqlOrder_2")->table('order' . $this->name, $cFunc);
            dump($this->name . '已添加');
        }
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        $cFunc = function (Blueprint $table) {
            $table->dropColumn('thirdOrderId');
            $table->dropColumn('thirdOrderSource');
        };

        // 分表库
        for ($i = 0; $i <= 99; $i++) {
            $this->name = '_' . str_pad($i, 3, 0, STR_PAD_LEFT);
            Schema::connection("mysqlOrder")->table('order' . $this->name, $cFunc);
            Schema::connection("mysqlOrder_2")->table('order' . $this->name, $cFunc);
            dump($this->name . '已删除');
        }
    }
}
